/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2007，所有权利保留。
 * 
 * 文件名：	OptionCollection.java
 * 模块说明：	
 * 修改历史：
 * 2007-3-15 - lxm - 创建。
 */
package com.hd123.rumba.option;

import java.util.ArrayList;
import java.util.List;

import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.exception.StringTooLongException;
import com.hd123.rumba.runtime.BaseEntity;
import com.hd123.rumba.user.IUser;

/**
 * 选项取值集合 | 实体 | 实现类
 * 
 * @author lxm
 * 
 */
public class OptionCollection extends BaseEntity implements IOptionCollection {

  private String optionalClassName;
  private IUser user = null;
  private Boolean locked = null;
  private Boolean online = null;
  private Boolean inherited = Boolean.TRUE;
  private List<IOptionItem> items = new ArrayList();

  public String toBizString() throws BusinessException {
    StringBuffer sb = new StringBuffer();
    sb.append(optionalClassName + " @");
    sb.append(" " + COptionCollection.CAPTION_DOMAIN + ":" + this.getDomain().getNameCode() + ";");
    sb.append(" " + COptionCollection.CAPTION_USER + ":" + this.getDomain().getNameCode() + ";");
    return sb.toString();
  }

  public IOptionItem getItemByName(String name) throws BusinessException {
    IOptionItem item = null;
    for (int i = 0; i < items.size(); i++)
      if (items.get(i).getName().equals(name)) {
        item = items.get(i);
        break;
      }
    return item;
  }

  public List<IOptionItem> getItems() {
    return items;
  }

  public void setItems(List<IOptionItem> items) {
    this.items = items;
  }

  public Boolean getLocked() {
    return locked;
  }

  public void setLocked(Boolean locked) {
    this.locked = locked;
  }

  public Boolean getOnline() {
    return online;
  }

  public void setOnline(Boolean online) {
    this.online = online;
  }

  public String getOptionalClassName() {
    return optionalClassName;
  }

  public void setOptionalClassName(String optionalClassName) throws StringTooLongException {
    if (optionalClassName != null)
      optionalClassName = truncate(optionalClassName, COptionCollection.LENGTH_OPTIONCLASSNAME,
          "optionalClassName", COptionCollection.CAPTION_OPTIONALCLASSNAME);
    this.optionalClassName = optionalClassName;
  }

  public IUser getUser() {
    return user;
  }

  public void setUser(IUser user) {
    this.user = user;
  }

  public Boolean getInherited() {
    return inherited;
  }

  public void setInherited(Boolean inherited) {
    this.inherited = inherited;
  }

}
